package com.karry.yl.web.baseinfo;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.karry.commons.Constants;
import com.karry.commons.base.SuperController;
import com.karry.yl.domain.baseinfo.PaymentInfo;
import com.karry.yl.service.baseinfo.PaymentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/organization/paymentinfo")
public class PaymentInfoController extends SuperController {
    @Autowired
    private PaymentInfoService paymentInfoService;

    @RequestMapping
    public String ui(HttpSession session){
        PaymentInfo paymentInfo = paymentInfoService.selectOne(new EntityWrapper<PaymentInfo>().eq("orgId", currentUser.getOrgId()));
        paymentInfo = (null != paymentInfo) ? paymentInfo : new PaymentInfo();
        session.setAttribute(Constants.SK_PAY_INFO,paymentInfo);
        return "baseinfo/paymentinfo";
    }

    @RequestMapping("/save")
    public String save(PaymentInfo paymentInfo,HttpSession session){
        paymentInfo.setOrgId(currentUser.getOrgId());
        if(null != paymentInfo.getId()){
            paymentInfoService.updateById(paymentInfo);
        }else {
            paymentInfoService.insert(paymentInfo);
        }
        session.setAttribute(Constants.SK_PAY_INFO,paymentInfo);
        return "redirect:/organization/paymentinfo";
    }
}
